// 异常处理

// 用class定义一个类并继承Error
class ArithmeticError extends Error {
    name = 'ArithmeticError';
    constructor(message){
        super(message);
    }
}

function divide(a, b) {
    if( b == 0 ) {
        // 创建Error实例
        let ex = new ArithmeticError("除数不能为零");
        // 抛出Error实例
        throw ex;
    }
    return a / b;
}

try{
    let res = divide(10, 2);
    console.log(res);
} catch (e){
    console.log( e.name, e.message );
} finally {
    console.log( 'finally' );
}

try{
    console.log( username );
} catch (e) {
    console.log(e.name, e.message);
}